Skip to content

绑定窗口 - BindWindow ​

函数简介 ​

绑定指定的窗口,并指定这个窗口的屏幕颜色获取方式,鼠标仿真模式,键盘仿真模式,以及模式设定

支持绑定沙盒程序(如 Sandboxie-Plus / 经典 Sandboxie)。若目标在沙盒内运行时出现绑定失败或 IPC 受限,可在沙盒配置(例如 Templates.ini 或当前沙盒的 Sandboxie.ini 中对应条目)的 [GlobalSettings] 段追加 OpenIpcPath 配置。路径中的 * 为沙盒通配符(匹配包含该片段的路径);请按实际要放行的进程名或路径修改其中的 TSVN 片段。可以通过SetConfig中的SharedMemoryNamePrefix来修改IPC前缀

配置示例:

ini
[GlobalSettings]
OpenIpcPath=*TSVN*

管理员权限:全局配置 EnsureElevated 默认为 true 时,本接口要求当前进程已 UAC 提升(管理员权限),否则绑定失败并返回 -2。绑定前可用 IsElevated 检测;若需关闭此限制,可通过 SetConfigByKey 设置 EnsureElevated=false(详见 SetConfig)。

接口名称 ​

BindWindow

DLL调用 ​

int BindWindow(long ola, long hwnd, string display, string mouse, string keyboard, int mode)

参数说明 ​

参数名类型说明
ola长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
hwnd长整数型指定的窗口句柄。display 含 "camera" 时可为 0。
display字符串屏幕颜色获取方式,详见下方说明。
mouse字符串鼠标仿真模式,详见下方说明。
keyboard字符串键盘仿真模式,详见下方说明。
public字符串通用绑定模式,详见下方说明。
mode整数型模式设定,详见下方说明。

display 屏幕颜色获取方式 ​

值说明
"normal"正常模式,前台截屏模式。
"gdi"GDI模式。
"gdi2"GDI2模式,兼容性较强但速度较慢。
"gdi3"GDI3模式,兼容性较强但速度较慢。
"gdi4"GDI4模式,支持小程序和浏览器截图。
"gdi5"GDI5模式,支持小程序和浏览器截图。
"dxgi"DXGI模式,支持小程序和浏览器截图,Windows10 1903及以上版本支持。
"dx.graphic.2d"dx.graphic.2d模式。
"dx.graphic.2d.2"dx.graphic.2d.2模式。
"dx.graphic.2d.3"dx.graphic.2d.3模式。
"dx.graphic.native"支持雷电模拟器,mumu模拟器后台截图原始数据。
"camera"绑定本机摄像头或 OBS Virtual Camera。hwnd 可为 0。设备与分辨率走 SetConfig 的 Camera*,详见下方「摄像头绑定」。不注入 Hook,且不要求管理员权限。
"vnc"VNC模式 (需要SetConfig接口中设置虚拟机端口)。
"dx"DX模式 (需要管理员权限)。
"vmware"虚拟机模式 (需要管理员权限。高级版功能,普通版无法使用)。

摄像头绑定(display=camera) ​

display 含 camera 时,画面来自本机摄像头,后续 Capture / FindPic 的坐标相对画面左上角。全图截图可传 0,0,0,0。

本接口内部走 BindWindowEx,public 为空,因此不能在这里加 dx.public.graphic.revert。需要上下翻转时改用 BindWindowEx。

摄像头参数只从 SetConfig / SetConfigByKey 读取,绑定时生效。改配置后需要重新绑定。

配置项说明
CameraIndex设备索引,默认 0。CameraName 非空时忽略。
CameraName友好名,支持 OBS Virtual Camera。空则用 CameraIndex。
CameraWidth / CameraHeight请求像素宽高。0 表示设备默认。
CameraFps请求帧率。0 表示设备默认。
CameraFourcc请求 FOURCC(MJPG / YUY2 / NV12 等)。空表示不指定。
CameraStricttrue 时请求宽高与实际不一致则绑定失败,返回 -4102。只比较宽高。
CameraBindTimeoutMs打开摄像头最大等待(毫秒),默认 8000。0 等同 8000。超时返回 -4104。

绑定前用 EnumCameras 看驱动报告的规格。绑定后:

cpp
ola.SetConfig("{\"CameraIndex\":0,\"CameraWidth\":1920,\"CameraHeight\":1080,"
              "\"CameraFps\":30.0,\"CameraFourcc\":\"MJPG\"}");
int ret = ola.BindWindow(0, "camera", "normal", "normal", 0);
ola.Capture(0, 0, 0, 0, "cam.png");

失败返回负数,摄像头相关为 -4101~-4104,见 BindWindow 错误码说明。

mouse 鼠标仿真模式 ​

值说明
"normal"正常模式,前台鼠标模式。
"windows"Windows模式,模拟windows消息。
"windows3"Windows3模式,模拟windows消息,适用于多窗口的进程。
"vnc"VNC模式 (需要SetConfig接口中设置虚拟机端口)。

dx模式组合(使用 | 连接):

值说明
"dx.mouse.position.lock.api"通过API锁定鼠标位置。
"dx.mouse.position.lock.message"通过消息锁定鼠标位置。
"dx.mouse.focus.input.api"通过API锁定鼠标输入焦点。
"dx.mouse.focus.input.message"通过消息锁定鼠标输入焦点。
"dx.mouse.clip.lock.api"通过API锁定刷新区域。
"dx.mouse.input.lock.api"通过API锁定鼠标输入接口。
"dx.mouse.state.api"通过API锁定鼠标输入状态。
"dx.mouse.state.message"通过消息锁定鼠标输入状态。
"dx.mouse.api"通过API模拟DX鼠标输入。
"dx.mouse.cursor"后台获取鼠标特征码。
"dx.mouse.raw.input"特殊窗口鼠标操作支持。
"dx.mouse.input.lock.api2"前台鼠标移动控制。
"dx.mouse.input.lock.api3"前台鼠标移动控制。
"dx.mouse.raw.input.active"配合raw.input的后台支持。
"dx.mouse.vmware"虚拟机鼠标穿透模式,目前只支持vm16、vm17 (高级版功能,普通版无法使用)。

keyboard 键盘仿真模式 ​

值说明
"normal"正常模式,前台键盘模式。
"windows"Windows模式,模拟windows消息。
"vnc"VNC模式 (需要SetConfig接口中设置虚拟机端口)。

dx模式组合(使用 | 连接):

值说明
"dx.keypad.input.lock.api"通过API锁定键盘输入接口。
"dx.keypad.state.api"通过API锁定键盘输入状态。
"dx.keypad.api"通过API模拟DX键盘输入。
"dx.keypad.raw.input"特殊窗口键盘操作支持。
"dx.keypad.raw.input.active"配合raw.input的后台支持。
"dx.keypad.api2"新的后台模拟形式。
"dx.keypad.vmware"虚拟机键盘穿透模式,目前只支持vm16、vm17 (高级版功能,普通版无法使用)。

mode 模式设定 ​

值说明
0推荐模式,通用性最好,后台效果最佳。
1远程线程注入。
2驱动注入模式1,当0、1无法使用时使用;内置欧拉驱动会自动加载。
3驱动注入模式2,当0、1无法使用时使用;内置欧拉驱动会自动加载。
4驱动注入模式3,当0、1无法使用时使用;内置欧拉驱动会自动加载。

示例 ​

SDK 调用 ​

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long hwnd = ola.FindWindow("", "记事本");
if (hwnd != 0) {
    int ret = ola.BindWindow(hwnd, "normal", "normal", "normal", 0);
      if (ret == 1) {
        // 绑定成功,可进行后台截图与键鼠操作
      }
}
csharp
using OLAPlug;

var ola = new OLAPlugServer();
long hwnd = ola.FindWindow("", "记事本");
if (hwnd != 0)
{
    int ret = ola.BindWindow(hwnd, "normal", "normal", "normal", 0);
      if (ret == 1)
    {
        // 绑定成功,可进行后台截图与键鼠操作
    }
}
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
hwnd = ola.FindWindow("", "记事本")
if hwnd != 0:
    ret = ola.BindWindow(hwnd, "normal", "normal", "normal", 0)
      if ret == 1:
        # 绑定成功,可进行后台截图与键鼠操作
        pass
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
long hwnd = ola.FindWindow("", "记事本");
if (hwnd != 0) {
    int ret = ola.BindWindow(hwnd, "normal", "normal", "normal", 0);
      if (ret == 1) {
        // 绑定成功,可进行后台截图与键鼠操作
      }
}
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
hwnd := ola.FindWindow("", "记事本")
if hwnd != 0 {
    ret := ola.BindWindow(hwnd, "normal", "normal", "normal", 0)
      if ret == 1 {
        // 绑定成功,可进行后台截图与键鼠操作
      }
}
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let hwnd = ola.find_window("", "记事本");
if hwnd != 0 {
    let ret = ola.bind_window(&hwnd, "normal", "normal", "normal", 0);
      if ret == 1 {
        // 绑定成功,可进行后台截图与键鼠操作
      }
}
cpp
var ola = com("OlaPlug.OlaSoft")
var hwnd = ola.FindWindow("", "记事本")
if (hwnd != 0) {
    var ret = ola.BindWindow(hwnd, "normal", "normal", "normal", 0)
      if (ret == 1) {
        // 绑定成功,可进行后台截图与键鼠操作
      }
}
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
hwnd = ola.FindWindow("", "记事本")
If hwnd <> 0 Then
    ret = ola.BindWindow(hwnd, "normal", "normal", "normal", 0)
      If ret = 1 Then
        ' 绑定成功,可进行后台截图与键鼠操作
    End If
End If
text
.局部变量 ola, OLAPlug
ola.创建 ()
hwnd = ola.FindWindow(““, “记事本“)
.如果真 (hwnd ≠ 0)
    ret = ola.BindWindow(hwnd, “normal“, “normal“, “normal“, 0)
      .如果真 (ret = 1)
        ' 绑定成功,可进行后台截图与键鼠操作
    .如果真结束
.如果真结束
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var hwnd = ola.FindWindow("", "记事本");
if (hwnd != 0) {
    var ret = ola.BindWindow(hwnd, "normal", "normal", "normal", 0);
      if (ret == 1) {
        // 绑定成功,可进行后台截图与键鼠操作
      }
}
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
长整数 hwnd = ola.FindWindow("", "记事本")
if (hwnd != 0) {
    整数 ret = ola.BindWindow(hwnd, "normal", "normal", "normal", 0)
      if (ret == 1) {
        // 绑定成功,可进行后台截图与键鼠操作
      }
}
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
long hwnd = ola.FindWindow("", "记事本");
if (hwnd != 0) {
    int ret = ola.BindWindow(hwnd, "normal", "normal", "normal", 0);
      if (ret == 1) {
        // 绑定成功,可进行后台截图与键鼠操作
      }
}

原生 DLL 调用 ​

cpp
long instance = CreateCOLAPlugInterFace();
long hwnd = 0;
// hwnd 可通过 FindWindow / EnumWindowByProcess 获取
BindWindow(instance, hwnd, "normal", "normal", "normal", 0);
csharp
long instance = CreateCOLAPlugInterFace();
long hwnd = 0;
// hwnd 可通过 FindWindow / EnumWindowByProcess 获取
BindWindow(instance, hwnd, "normal", "normal", "normal", 0);
python
from ctypes import CDLL, c_int, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
hwnd = 0
# hwnd 可通过 FindWindow / EnumWindowByProcess 获取
BindWindow(instance, hwnd, "normal", "normal", "normal", 0)

返回值 ​

返回值说明
1成功。
负数失败;绝对值为错误码。与 BindWindowEx 相同。

详见 BindWindow 错误码说明。

注意事项 ​

项目说明
管理员权限全局 EnsureElevated 默认 true:未以管理员权限(UAC 已提升)运行则绑定失败,返回 -4004。display 含 "camera" 时不做这项校验。部分 display/mode 组合(如 "dx"、"vmware")本身也依赖提升权限。
EnsureElevated设置为 false 可关闭绑定前的管理员校验(见 SetConfigByKey / SetConfig)。
IsElevated建议绑定前调用 IsElevated,返回 1 表示已提升。
DownCpu绑定 DX 图色后可用 DownCpu 降低目标进程 CPU。
默认 Callmode=2/3/4/10 驱动自带注入不受 SetMemoryCallMode 影响。
摄像头display="camera" 的设备、分辨率、帧率、FOURCC 只走 SetConfig 的 Camera*。hwnd 可为 0。本接口 public 为空,需要上下翻转时用 BindWindowEx 的 dx.public.graphic.revert。